<?
$page = $db->EscapeString($_GET['pg']);
$edit = $db->EscapeString($_GET['edit']);
$del = $db->EscapeString($_GET['del']);

if(!isset($page)){
	$sql = $db->FetchArray($db->Query("SELECT user,site,title,points,cpc,banned FROM `sites` WHERE `id`='".$edit."'"));
	$user = $sql['user'];
	$site = $sql['site'];
	$s_title = $sql['title'];
	$coins = $sql['points'];
	$status = $sql['banned'];
	$cpc = $sql['cpc'];
	if(isset($_POST['submit'])){
		$db->Query("UPDATE `sites` SET `user`='{$_POST['user']}', `site`='{$_POST['url']}', `title`='{$_POST['title']}', `points`='{$_POST['coins']}', `cpc`='{$_POST['cpc']}', `banned`='{$_POST['status']}' WHERE `id`='".$edit."'");
		$mesaj = "<div class=\"message success\"><h3>Success!</h3><p>Site successfully edited!</p></div>";
	}
	if($del != "" && is_numeric($del)){$db->Query("DELETE FROM `sites` WHERE `id`='".$del."'");}
}elseif($page == 1){
	$sql = $db->FetchArray($db->Query("SELECT user,facebook,title,points,cpc,active FROM `facebook` WHERE `id`='".$edit."'"));
	$user = $sql['user'];
	$site = $sql['facebook'];
	$s_title = $sql['title'];
	$coins = $sql['points'];
	$status = $sql['active'];
	$cpc = $sql['cpc'];
	if(isset($_POST['submit'])){
		$db->Query("UPDATE `facebook` SET `user`='{$_POST['user']}', `facebook`='{$_POST['url']}', `title`='{$_POST['title']}', `points`='{$_POST['coins']}', `cpc`='{$_POST['cpc']}', `active`='{$_POST['status']}' WHERE `id`='".$edit."'");
		$mesaj = "<div class=\"message success\"><h3>Success!</h3><p>Facebook successfully edited!</p></div>";
	}
	if($del != "" && is_numeric($del)){$db->Query("DELETE FROM `facebook` WHERE `id`='".$del."'");}
}elseif($page == 2){
	$sql = $db->FetchArray($db->Query("SELECT user,t_name,points,cpc,active FROM `twitter` WHERE `id`='".$edit."'"));
	$user = $sql['user'];
	$site = $sql['t_name'];
	$coins = $sql['points'];
	$status = $sql['active'];
	$cpc = $sql['cpc'];
	if(isset($_POST['submit'])){
		$db->Query("UPDATE `twitter` SET `user`='{$_POST['user']}', `t_name`='{$_POST['url']}', `points`='{$_POST['coins']}', `cpc`='{$_POST['cpc']}', `active`='{$_POST['status']}' WHERE `id`='".$edit."'");
		$mesaj = "<div class=\"message success\"><h3>Success!</h3><p>Twitter successfully edited!</p></div>";
	}
	if($del != "" && is_numeric($del)){$db->Query("DELETE FROM `twitter` WHERE `id`='".$del."'");}
}elseif($page == 3){
	$sql = $db->FetchArray($db->Query("SELECT user,youtube,title,points,cpc,active FROM `youtube` WHERE `id`='".$edit."'"));
	$user = $sql['user'];
	$site = $sql['youtube'];
	$s_title = $sql['title'];
	$coins = $sql['points'];
	$status = $sql['active'];
	$cpc = $sql['cpc'];
	if(isset($_POST['submit'])){
		$db->Query("UPDATE `youtube` SET `user`='{$_POST['user']}', `youtube`='{$_POST['url']}', `title`='{$_POST['title']}', `points`='{$_POST['coins']}', `cpc`='{$_POST['cpc']}', `active`='{$_POST['status']}' WHERE `id`='".$edit."'");
		$mesaj = "<div class=\"message success\"><h3>Success!</h3><p>Youtube successfully edited!</p></div>";
	}
	if($del != "" && is_numeric($del)){$db->Query("DELETE FROM `youtube` WHERE `id`='".$del."'");}
}elseif($page == 4){
	$sql = $db->FetchArray($db->Query("SELECT user,site,title,points,cpc,active FROM `surf` WHERE `id`='".$edit."'"));
	$user = $sql['user'];
	$site = $sql['site'];
	$s_title = $sql['title'];
	$coins = $sql['points'];
	$status = $sql['active'];
	$cpc = $sql['cpc'];
	if(isset($_POST['submit'])){
		$db->Query("UPDATE `surf` SET `user`='{$_POST['user']}', `site`='{$_POST['url']}', `title`='{$_POST['title']}', `points`='{$_POST['coins']}', `cpc`='{$_POST['cpc']}', `active`='{$_POST['status']}' WHERE `id`='".$edit."'");
		$mesaj = "<div class=\"message success\"><h3>Success!</h3><p>Website successfully edited!</p></div>";
	}
	if($del != "" && is_numeric($del)){$db->Query("DELETE FROM `surf` WHERE `id`='".$del."'");}
}elseif($page == 5){
	$sql = $db->FetchArray($db->Query("SELECT user,t_name,points,cpc,banned FROM `digg` WHERE `id`='".$edit."'"));
	$user = $sql['user'];
	$site = $sql['t_name'];
	$coins = $sql['points'];
	$status = $sql['banned'];
	$cpc = $sql['cpc'];
	if(isset($_POST['submit'])){
		$db->Query("UPDATE `digg` SET `user`='{$_POST['user']}', `t_name`='{$_POST['url']}', `points`='{$_POST['coins']}', `cpc`='{$_POST['cpc']}', `banned`='{$_POST['status']}', `cpc`='{$_POST['cpc']}' WHERE `id`='{$edit}'");
		$mesaj = "<div class=\"message success\"><h3>Success!</h3><p>Digg successfully edited!</p></div>";
	}
	if($del != "" && is_numeric($del)){$db->Query("DELETE FROM `digg` WHERE `id`='".$del."'");}
	
	
}elseif($page == 6){
	$sql = $db->FetchArray($db->Query("SELECT user,site,title,visits,active,points,cpc FROM `tweet` WHERE `id`='".$edit."'"));
	$user = $sql['user'];
	$site = $sql['site'];
    $title = $sql['title'];
	$coins = $sql['points'];
	$status = $sql['banned'];
	$cpc = $sql['cpc'];
	if(isset($_POST['submit'])){
		$db->Query("UPDATE `tweet` SET `user`='{$_POST['user']}', `t_name`='{$_POST['url']}', `points`='{$_POST['coins']}', `cpc`='{$_POST['cpc']}', `banned`='{$_POST['status']}', `cpc`='{$_POST['cpc']}' WHERE `id`='{$edit}'");
		$mesaj = "<div class=\"message success\"><h3>Success!</h3><p>Digg successfully edited!</p></div>";
	}
	
	if($del != "" && is_numeric($del)){$db->Query("DELETE FROM `tweet` WHERE `id`='".$del."'");}
	
	
	
	
}elseif($page == 7){
	$sql = $db->FetchArray($db->Query("SELECT id,user,y_name,y_link,y_av,earned,active,points,cpc FROM `ytsubs` WHERE `id`='".$edit."'"));
	$user = $sql['user'];
	$site = $sql['y_name'];
    $title = $sql['y_link'];
	$coins = $sql['points'];
	$status = $sql['banned'];
	$cpc = $sql['cpc'];
	if(isset($_POST['submit'])){
		$db->Query("UPDATE `ytsubs` SET `user`='{$_POST['user']}', `t_name`='{$_POST['url']}', `points`='{$_POST['coins']}', `cpc`='{$_POST['cpc']}', `banned`='{$_POST['status']}', `cpc`='{$_POST['cpc']}' WHERE `id`='{$edit}'");
		$mesaj = "<div class=\"message success\"><h3>Success!</h3><p>Digg successfully edited!</p></div>";
	}
	if($del != "" && is_numeric($del)){$db->Query("DELETE FROM `ytsubs` WHERE `id`='".$del."'");}
	
}elseif($page == 8){
	$sql = $db->FetchArray($db->Query("SELECT id,user,site,title,visits,active,points,cpc FROM `stumbleupon` WHERE `id`='".$edit."'"));
	$user = $sql['user'];
	$site = $sql['site'];
    $title = $sql['title'];
	$coins = $sql['points'];
	$status = $sql['banned'];
	$cpc = $sql['cpc'];
	if(isset($_POST['submit'])){
		$db->Query("UPDATE `stumbleupon` SET `user`='{$_POST['user']}', `site`='{$_POST['url']}', `points`='{$_POST['coins']}', `cpc`='{$_POST['cpc']}', `banned`='{$_POST['status']}', `cpc`='{$_POST['cpc']}' WHERE `id`='{$edit}'");
		$mesaj = "<div class=\"message success\"><h3>Success!</h3><p>SutmbleUpon successfully edited!</p></div>";
	}
	if($del != "" && is_numeric($del)){$db->Query("DELETE FROM `stumbleupon` WHERE `id`='".$del."'");}
}


?>
            <div id="page-subheader">
                <div class="wrapper clearfix">
                    <nav id="sub-nav">
					<ul>
                            <li><a href="index.php?x=sites">Google</a></li>
                            <li><a href="index.php?x=sites&pg=1">Facebook</a></li>
                            <li><a href="index.php?x=sites&pg=2">Twitter</a></li>
							<li><a href="index.php?x=sites&pg=5">Digg</a></li>
							<li><a href="index.php?x=sites&pg=3">Youtube</a></li>
							<li><a href="index.php?x=sites&pg=4">Surf</a></li>
							<li><a href="index.php?x=sites&pg=6">Tweets</a></li>
							<li><a href="index.php?x=sites&pg=7">YouTube Subscribers</a></li>
							<li><a href="index.php?x=sites&pg=8">StumbleUpon Followers</a></li>
                        </ul>
                    </nav>
                </div>
            </div>
        </header>
        <section id="content">
            <div class="wrapper">
                <section class="grid_6 first top">
                    <div class="columns leading">
                        <div class="grid_6 first"><? if($edit != ""){ echo $mesaj;?>
						<form id="form" method="post" class="form widget">
                                <header><h2>Edit</h2></header>
                                <section>                 
                                    <fieldset>
                                         <dl>
                                             <dt></dt><dd><label>User</label><input type="text" name="user" value="<?=(isset($_POST['user']) ? $_POST['user'] : $user)?>" required="required" /></dd>
											 <dt></dt><dd><label>URL</label><input type="text" name="url" value="<?=(isset($_POST['url']) ? $_POST['url'] : $site)?>" required="required" /></dd>
											 <?if($page != 2 && $page != 8){?><dt></dt><dd><label>Title</label><input type="text" name="title" value="<?=(isset($_POST['title']) ? $_POST['title'] : $s_title)?>" required="required" /></dd><?}?>
                                             <dt></dt><dd><label>Coins</label><input type="text" name="coins" value="<?=(isset($_POST['coins']) ? $_POST['coins'] : $coins)?>" required="required" /></dd>
											  <dt></dt><dd><label>CPC</label><input type="text" name="cpc" value="<?=(isset($_POST['cpc']) ? $_POST['cpc'] : $cpc)?>" required="required" /></dd>
                                             <dt></dt><dd><label>Status</label><select name="status"><option value="0">Active</option><option value="1"<?=($status != 0 ? ' selected' : '')?>>Banned</option></select></dd>
                                     	</dl>    
                                     </fieldset>
                                     <hr />
                                     <button class="button button-green" type="submit" name="submit">Submit</button>
                                     <button class="button button-gray" type="reset">Reset</button>
                                </section>
                            </form><?}else{?>
                            <table class="datatable sortable selectable paginate full">
                                <thead>
                                    <tr>
                                        <th width="25">ID</th>
                                        <th>User</th>
                                        <th>Page</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
								<tfoot>
                                    <tr>
                                        <th width="25">ID</th>
                                        <th>User</th>
                                        <th>Website</th>
                                        <th>Actions</th>
                                    </tr>
                                </tfoot>
                                <tbody>
<? if(!isset($page)){
  $sites2 = $db->Query("SELECT id,user,site FROM `sites` ORDER BY `id` ASC");
  for($j=$begin+1; $sites = $db->FetchArray($sites2); $j++)
{
?>	
                                    <tr>
                                        <td><?=$sites['id']?></td>
                                        <td><?=$sites['user']?></td>
                                        <td><a href="<?=$sites['site']?>" target="_blank"><?=$sites['site']?></a></td>
										<td><ul class="action-buttons">
                                        <li><a href="index.php?x=sites&edit=<?=$sites['id']?>" class="action-button" title="Edit site"><span class="pencil"></span></a></li>
										<li><a href="index.php?x=sites&del=<?=$sites['id']?>" class="action-button" title="Delete site"><span class="delete"></span></a></li></ul></td>
                                    </tr>
<?}}else if($page == 1){
  $sites2 = $db->Query("SELECT id,user,facebook FROM `facebook` ORDER BY `id` ASC");
  for($j=1; $sites = $db->FetchArray($sites2); $j++)
{
$usr = $db->FetchArray($db->Query("SELECT login FROM `users` WHERE `id`='".$sites['user']."'"));
?>	
                                    <tr>
                                        <td><?=$sites['id']?></td>
                                        <td><?=$usr['login']?></td>
                                        <td><a href="<?=$sites['facebook']?>" target="_blank"><?=$sites['facebook']?></a></td>
										<td><ul class="action-buttons">
                                        <li><a href="index.php?x=sites&pg=1&edit=<?=$sites['id']?>" class="action-button" title="Edit site"><span class="pencil"></span></a></li>
										<li><a href="index.php?x=sites&pg=1&del=<?=$sites['id']?>" class="action-button" title="Delete site"><span class="delete"></span></a></li></ul></td>
                                    </tr>
<?}}else if($page == 2){
  $sites2 = $db->Query("SELECT id,user,t_name FROM `twitter` ORDER BY `id` ASC");
  for($j=1; $sites = $db->FetchArray($sites2); $j++)
{
$usr = $db->FetchArray($db->Query("SELECT login FROM `users` WHERE `id`='".$sites['user']."'"));
?>	
                                    <tr>
                                        <td><?=$sites['id']?></td>
                                        <td><?=$usr['login']?></td>
                                        <td><a href="http://twitter.com/<?=$sites['t_name']?>" target="_blank"><?=$sites['t_name']?></a></td>
										<td><ul class="action-buttons">
                                        <li><a href="index.php?x=sites&pg=2&edit=<?=$sites['id']?>" class="action-button" title="Edit site"><span class="pencil"></span></a></li>
										<li><a href="index.php?x=sites&pg=2&del=<?=$sites['id']?>" class="action-button" title="Delete site"><span class="delete"></span></a></li></ul></td>
                                    </tr>
<?}}else if($page == 3){
  $sites2 = $db->Query("SELECT id,user,youtube FROM `youtube` ORDER BY `id` ASC");
  for($j=1; $sites = $db->FetchArray($sites2); $j++)
{
$usr = $db->FetchArray($db->Query("SELECT login FROM `users` WHERE `id`='".$sites['user']."'"));
?>	
                                    <tr>
                                        <td><?=$sites['id']?></td>
                                        <td><?=$usr['login']?></td>
                                        <td><a href="http://www.youtube.com/watch?v=<?=$sites['youtube']?>" target="_blank"><?=$sites['youtube']?></a></td>
										<td><ul class="action-buttons">
                                        <li><a href="index.php?x=sites&pg=3&edit=<?=$sites['id']?>" class="action-button" title="Edit site"><span class="pencil"></span></a></li>
										<li><a href="index.php?x=sites&pg=3&del=<?=$sites['id']?>" class="action-button" title="Delete site"><span class="delete"></span></a></li></ul></td>
                                    </tr>
<?}}else if($page == 4){
  $sites2 = $db->Query("SELECT id,user,site FROM `surf` ORDER BY `id` ASC");
  for($j=1; $sites = $db->FetchArray($sites2); $j++)
{
$usr = $db->FetchArray($db->Query("SELECT login FROM `users` WHERE `id`='".$sites['user']."'"));
?>	
                                    <tr>
                                        <td><?=$sites['id']?></td>
                                        <td><?=$usr['login']?></td>
                                        <td><a href="<?=$sites['site']?>" target="_blank"><?=$sites['site']?></a></td>
										<td><ul class="action-buttons">
                                        <li><a href="index.php?x=sites&pg=4&edit=<?=$sites['id']?>" class="action-button" title="Edit site"><span class="pencil"></span></a></li>
										<li><a href="index.php?x=sites&pg=4&del=<?=$sites['id']?>" class="action-button" title="Delete site"><span class="delete"></span></a></li></ul></td>
                                    </tr>
<?}}else if($page == 5){
  $sites2 = $db->Query("SELECT id,user,t_name FROM `digg` ORDER BY `id` ASC");
  for($j=1; $sites = $db->FetchArray($sites2); $j++)
{
$usr = $db->FetchArray($db->Query("SELECT login FROM `users` WHERE `id`='".$sites['user']."'"));
?>	
                                    <tr>
                                        <td><?=$sites['id']?></td>
                                        <td><?=$usr['login']?></td>
                                        <td><a href="http://digg.com/<?=$sites['t_name']?>" target="_blank"><?=$sites['t_name']?></a></td>
										<td><ul class="action-buttons">
                                        <li><a href="index.php?x=sites&pg=5&edit=<?=$sites['id']?>" class="action-button" title="Edit site"><span class="pencil"></span></a></li>
										<li><a href="index.php?x=sites&pg=5&del=<?=$sites['id']?>" class="action-button" title="Delete site"><span class="delete"></span></a></li></ul></td>
                                    </tr>
<?}}else if($page == 6){
  $sites2 = $db->Query("SELECT id,user,site,title FROM `tweet` ORDER BY `id` ASC");
  for($j=1; $sites = $db->FetchArray($sites2); $j++)
{
$usr = $db->FetchArray($db->Query("SELECT login FROM `users` WHERE `id`='".$sites['user']."'"));
?>	
                                    <tr>
                                        <td><?=$sites['id']?></td>
                                        <td><?=$usr['login']?></td>
                                        <td><a href="<?=$sites['site']?>" target="_blank"><?=$sites['site']?></a><br /><?=$sites['title']?></td>
										<td><ul class="action-buttons">
                                        <li><a href="index.php?x=sites&pg=6&edit=<?=$sites['id']?>" class="action-button" title="Edit site"><span class="pencil"></span></a></li>
										<li><a href="index.php?x=sites&pg=6&del=<?=$sites['id']?>" class="action-button" title="Delete site"><span class="delete"></span></a></li></ul></td>
                                    </tr>


<?}}else if($page == 7){
  $sites2 = $db->Query("SELECT id,user,y_name,y_link FROM `ytsubs` ORDER BY `id` ASC");
  for($j=1; $sites = $db->FetchArray($sites2); $j++)
{
$usr = $db->FetchArray($db->Query("SELECT login FROM `users` WHERE `id`='".$sites['user']."'"));
?>	
                                    <tr>
                                        <td><?=$sites['id']?></td>
                                        <td><?=$usr['login']?></td>
                                        <td><a href="http://youtube.com/<?=$sites['y_name']?>" target="_blank"><?=$sites['y_name']?></a><br /><?=$sites['y_link']?></td>
										<td><ul class="action-buttons">
                                        <li><a href="index.php?x=sites&pg=7&edit=<?=$sites['id']?>" class="action-button" title="Edit site"><span class="pencil"></span></a></li>
										<li><a href="index.php?x=sites&pg=7&del=<?=$sites['id']?>" class="action-button" title="Delete site"><span class="delete"></span></a></li></ul></td>
                                    </tr>
									
									
									<?}}else if($page == 8){
  $sites2 = $db->Query("SELECT id,user,site,title FROM `stumbleupon` ORDER BY `id` ASC");
  for($j=1; $sites = $db->FetchArray($sites2); $j++)
{
$usr = $db->FetchArray($db->Query("SELECT login FROM `users` WHERE `id`='".$sites['user']."'"));
?>	
                                    <tr>
                                        <td><?=$sites['id']?></td>
                                        <td><?=$usr['login']?></td>
                                        <td><a href="<?=$sites['site']?>" target="_blank"><?=$sites['site']?></a><br /><?=$sites['title']?></td>
										<td><ul class="action-buttons">
                                        <li><a href="index.php?x=sites&pg=8&edit=<?=$sites['id']?>" class="action-button" title="Edit site"><span class="pencil"></span></a></li>
										<li><a href="index.php?x=sites&pg=8&del=<?=$sites['id']?>" class="action-button" title="Delete site"><span class="delete"></span></a></li></ul></td>
                                    </tr>
									
<?}}?>
                                </tbody>
                            </table><?}?>
                        </div>
                    </div>

                    <div class="clear">&nbsp;</div>
                </section>

                <aside class="grid_2 top">
                    <div class="accordion">
                        <header class="current"><h2>Info</h2></header>
                        <section style="display:block">
                            Here you can manage all pages!
                        </section>
                    </div>
                </aside>

                <div class="clear"></div>

            </div>
            <div id="push"></div>
        </section>
    </div>
    
    <footer id="page-footer">
        <div id="footer-inner">
            <p class="wrapper">All rights reserved &copy; <a href="http://mafianet.org" target="_blank">MafiaNet</a> <?=date('Y')?></p>
        </div>
    </footer>
</body>
</html>